#--
# Copyright (c) 2007 Mathew Abonyi
# Please read LICENSE document for more information.
#++

module Retrospectiva
  module Extension
    module SCMTicketUpdate

      # This extension to the TicketChange model adds a convenient method
      # for creating changes out of tickets which have already had values
      # changed.
      module TicketChangeExtension
        
        def self.included(base)
          base.extend ClassMethods
        end
        
        module ClassMethods
          
          # Creates a TicketChange record from a ticket which already has
          # its changes made. Optionally takes a TicketReference object.
          def new_from_ticket(ticket)
            change = new
            change.ticket_id = ticket.id
            change.changes = ticket.changed_attributes
            change
          end
        end

      end
    end
  end
end

TicketChange.send(:include, Retrospectiva::Extension::SCMTicketUpdate::TicketChangeExtension)